﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Catering_Rules;
using System.Text;
using System.Collections;
using System.Web.Services;

namespace Catering.Catering_Page.Caipin.Caipin_jcsz
{
    public partial class Yuanliaoshezhi : System.Web.UI.Page
    {
        View_Operaction_Common voc = new View_Operaction_Common();
        public DataTable dt_RawMaterials = new DataTable();
        public DataTable dt_RawMaterialsInfo = new DataTable();
        public DataTable dt_RawMaterial = new DataTable();
        public int m_dishNum = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.btn_delyuanliao.Attributes.Add("onclick", "return confirm(\"你确认要删除吗？\")");
            }
            this.LoadData();
        }

        public void LoadData()
        {
            this.dt_RawMaterials = new Catering_Rules.T_RawMaterials().GetAllList().Tables[0];
            this.dt_RawMaterialsInfo = new Catering_Rules.RawMaterialsInfo().GetAllList().Tables[0];
        }

        //删除选中的原料
        protected void btn_delyuanliao_Click(object sender, ImageClickEventArgs e)
        {
            string YuanLiaoID = this.HidID.Value;
            int id = 0;
            Int32.TryParse(YuanLiaoID, out id);
            if (id <= 0) return;
            DataTable dt_IndbInfo = new Catering_Rules.InDbInfo().GetList(" RAWID= " + id+" ").Tables[0];
            if (dt_IndbInfo.Rows.Count > 0)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('此原料已入库，删除失败！')</script>");
                return;
            }

            new Catering_Rules.RoomWaing().DeleteListBywhere("RAWID=" + YuanLiaoID);
            new Catering_Rules.RawMaterial_Area().DeleteListBywhere("RawID=" + YuanLiaoID);
            new Catering_Rules.RawMaterial_Unit().DeleteListBywhere("RawMaterialID=" + YuanLiaoID);
            bool B_YingYang = new NutrientComposition().DeleteListBywhere("RawID=" + YuanLiaoID);
            bool B_XiangXi = new RAEInfo().DeleteListBywhere("RawID=" + YuanLiaoID);
            if (new T_RawMaterial().Delete(Convert.ToInt32(YuanLiaoID)))
            {
                Response.Redirect("Yuanliaoshezhi.aspx");
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('删除失败！')</script>");
            }
        }

        [WebMethod]
        public static ArrayList GetRawName(string InDBId)
        {
            ArrayList al = new ArrayList();
            DataTable dt_RawArea = new Catering_Rules.RawMaterial_Area().GetList("InDBId='" + InDBId + "'").Tables[0];
            if (dt_RawArea != null && dt_RawArea.Rows.Count > 0)
            {
                for (int i = 0; i < dt_RawArea.Rows.Count; i++)
                {
                    int rawid = Convert.ToInt32(dt_RawArea.Rows[i]["RawID"]);
                    if (rawid > 0) al.Add(rawid);
                }
                dt_RawArea.Dispose();
            }
            return al;
        }
    }
}